'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, BOOLEAN } = app.Sequelize;

  const User = app.model.define('user', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    nickname: STRING(100),
    avatar: STRING(255),
    phone: STRING(20),
    sex: INTEGER,
    height: STRING(50),
    birthday: STRING(100),
    age: INTEGER,
    province_id: INTEGER,
    province: STRING(100),
    city_id: INTEGER,
    city: STRING(100),
    area_id: INTEGER,
    area: STRING(100),
    longitude: STRING(50),
    latitude: STRING(50),
    position: STRING(100),
    school: STRING(100),
    company: STRING(100),
    profession: STRING(100),
    purpose: STRING(100),
    constellation: STRING(100),
    daily: STRING(1000),
    vip: BOOLEAN,
    finish: STRING(50),
    wish: STRING(1000),
    open_time: DATE,
    expire_time: DATE,
    vip_like: INTEGER,
    get_like: INTEGER,
    use_like: INTEGER,
    success_invite: INTEGER,
    marry_like: STRING(1000),
    wxapp_openid: STRING(100),
    token: STRING(1000),
    identity: INTEGER,
    education: INTEGER,
    create_time: DATE,
    update_time: DATE,
    delete_time: DATE
  }, {
    timestamps: true,
    paranoid: true,
    createdAt: 'create_time',
    updatedAt: 'update_time',
    deletedAt: 'delete_time'
  });

  User.associate = function() {
    app.model.User.hasMany(app.model.UserImage, {
      as: 'images', 
      foreignKey: 'user_id', 
      targetKey: 'id'
    });

    app.model.User.belongsTo(app.model.UserCertificate, {
      as: 'certificate', 
      foreignKey: 'id', 
      targetKey: 'user_id'
    });;
  };

  return User;
};
